<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html >
<html>
	<head>
		<%@ include file="/common/taglibs.jsp"%>
		<title>sinlog</title>
	</head>
	<body>
		<div class="mainContent">
			<div class="searDiv">
				<table class="searTb">
					<tr>
						<td><table>
							<tr>
								<td width="100" align="right"><label>任务名称：</label></td>
								<td><input id="q_taskName" type="text" /></td>
								<td width="100" align="right"><label>任务类型：</label></td>
								<td><sl:paramSelect paramType="<%=SinlogConstants.TASK_TYPE%>" id="q_taskType" style="width:100px" blank="true"/></td>
							</tr>
						</table></td>
						<td width="200"><a href="javascript:doQuery();" class="button blue">查询</a></td>
					</tr>
				</table>
			</div>
			<div class="dgDiv">
				<table id="dg"></table> 
			</div>
		</div>
<script type="text/javascript">
	$(document).ready(function(){
		$('#dg').datagrid({   
		    url:'${ctx}/task!list.action',   
		    pagination:true,
		    height: getDgH('dgDiv') - 55,
		    pageSize:30,
		    pageList:[30,60,100,200], 
		    columns:[[   
				{checkbox:true,field:'ck'},
		        {title:'任务名',field:'taskName',width:150},
		        {title:'任务类型',field:'taskType',width:80,formatter:function(val,row,index){
		        	return format(<%=ParamServiceUtil.getFormatMap(SinlogConstants.TASK_TYPE)%>,val); 
		        }},
		        {title:'关键字',field:'contentKey',width:150},
		        {title:'CLASS',field:'classKey',width:300},
		        {title:'最后结果时间',field:'lastDate',width:150,formatter:function(val,row,index){
		        	return formatDate(val);
		        }},
		        {title:'最后结果',field:'lastRs',width:100},
		        {field:'editor',title:'操作',width:100,align:'center',formatter:function(value,row,index){
					var ed = '<a class="dicon icon-search" title="详细" onclick=goView(\''+row.taskId+'\')></a>&nbsp;';
					ed += '<a class="dicon icon-remove" title="删除" onclick=goDelete('+null+',\''+row.taskId+'\')></a>&nbsp;';
					ed += '<a class="dicon icon-refresh" title="重启任务" onclick=goRestart(\''+row.taskId+'\')></a>&nbsp;';
					ed += '<a class="dicon icon-no" title="停止任务" onclick=goStop(\''+row.taskId+'\')></a>';
					return ed;
				}}
		    ]],
		    toolbar:[{
		    	text:'新增',  
				iconCls: 'icon-add',
				handler: goAdd
			},{
		    	text:'删除',  
				iconCls: 'icon-remove',
				handler: goDelete
			}],
		    queryParams:{
		       'q_taskName_eq_s': $('#q_taskName').val(),
		       'q_taskType_eq_s': $('#q_taskType').val()
		   	},
		   	onDblClickRow:function(rowIndex, rowData){
		   		goView(rowData.taskId);
		   	}
		}); 
	});
	function doQuery(){
		var queryParams = $('#dg').datagrid('options').queryParams;
	    queryParams["q_taskName_eq_s"] = $('#q_taskName').val();
	    queryParams["q_taskType_eq_s"] = $('#q_taskType').val();

	    $('#dg').datagrid('options').pageNumber = 1;
	    var p = $('#dg').datagrid('getPager');
	    if (p){
	        $(p).pagination({
	           pageNumber:1,
	           pageSize:30
	        });
	        queryParams["rows"] = 30;
	        queryParams["page"] = 1;
	    }
	    $('#dg').datagrid('reload');
	}
	function goAdd(){
		openMenu('任务管理-新增任务','${ctx}/task!add.action');
	}
	function goView(id){
		openMenu('任务管理-查看任务','${ctx}/task!view.action?task.taskId='+id);
	}
	function goRestart(id){
		wait();
		Util.doAjaxPost('${ctx}/task!restart.action',{'task.taskId':id},function(text){
			uwait();
			var ret = jQuery.parseJSON(text);
			if(ret.success){
				$.messager.alert('系统提示','操作成功！','info');
			}else{
				$.messager.alert('系统提示',ret.msg,'error');
			}
		});
	}
	
	function goStop(id){
		wait();
		Util.doAjaxPost('${ctx}/task!stop.action',{'task.taskId':id},function(text){
			uwait();
			var ret = jQuery.parseJSON(text);
			if(ret.success){
				$.messager.alert('系统提示','操作成功！','info');
			}else{
				$.messager.alert('系统提示',ret.msg,'error');
			}
		});
	}
	function goDelete(event,id){
		var ids = '';
		if(id){
			ids = id;
		}else{
			var ids = getCkIds('dg','taskId');
		}
		if(ids == ''){
			$.messager.alert('系统提示','请选择要操作的记录！','info');
		}else{
			$.messager.confirm('系统提示','确定执行该操作？',function(r){
				if(r){
					wait();
					Util.doAjaxPost('${ctx}/task!delete.action',{ids:ids},function(text){
						uwait();
						var ret = jQuery.parseJSON(text);
						if(ret.success){
							doQuery();
						}else{
							$.messager.alert('系统提示','操作失败！','error');
						}
					});
				}
			});
		}
	}
</script>
	</body>
</html>